package engine

import (
	"awesomeProject/crawler/fetcher"
	"log"
)

func Run(seeds ...Request) {
	var requests []Request
	for _, r := range seeds {
		requests = append(requests, r)
	}
	for len(requests) > 0 {
		r := requests[0]
		requests = requests[1:]
		if body := fetcher.Fetch(r.Url); body != "" {
			result := r.Parser(body)
			requests = append(requests, result.Requests...)
			for _, v := range result.Items {
				log.Printf("Got item %v\n", v)
			}
		}
	}
}
